package br.ita.battlefarm.core;

import java.util.ArrayList;

import br.ita.battlefarm.pieces.Piece;
import br.ita.battlefarm.views.SetupBuilderView;

import android.content.Context;
import android.view.View;

public class HumanSetupBuilder {
	private ArrayList<Piece> piecesSet;
	private SetupBuilderView builderView;
	
	public HumanSetupBuilder( ArrayList<Class> pieceSet ){
		piecesSet = new ArrayList<Piece>();
		for( Class classe : pieceSet ){
			try {
				piecesSet.add((Piece)classe.newInstance());
			} catch (IllegalAccessException e) {
				
			} catch (InstantiationException e) {
				
			}
		}
	}

	public View createView(Context activity) {
		builderView = new SetupBuilderView(activity,this);
		return builderView;
	}

	public View getView(){
		return builderView;
	}
	
	public void rotateNextPiece(){
		if( !piecesSet.isEmpty() ){
			piecesSet.get(0).rotateRight();
		}
	}

	public Piece getNextPiece() {
		if( piecesSet.isEmpty() ){
			return null;
		}
		return piecesSet.get(0);
	}

	public void discardNextPiece() {
		piecesSet.remove(0);
		builderView.invalidate();
	}
	
}
